from Project.HTools.encry.url.url_panel import URLPanel
import wx
import urllib.parse


class URLMain(URLPanel):
    def __init__(self, parent):
        URLPanel.__init__(self, parent)
        self.edit_result.SetEditable(False)

    def encode(self, event):
        if self.edit_input.GetValue() == '':
            self.alertMessage('输入的内容不能为空')
            return
        input = self.edit_input.GetValue()
        self.edit_result.SetValue(urllib.parse.quote(input))

    def clear_input(self, event):
        self.edit_input.SetValue('')
        self.edit_result.SetValue('')

    def decode(self, event):
        if self.edit_input.GetValue() == '':
            self.alertMessage('输入的内容不能为空')
            return
        input = self.edit_input.GetValue()
        self.edit_result.SetValue(urllib.parse.unquote(input))

    def alertMessage(self, message):
        wx.MessageDialog(self, message, '操作提醒', wx.OK).ShowModal()
